<template>
    <view class="pub_page pub_page_bg pub_chat_add pub_header_padding">
        <pub-head headerName="chat_add" :headerConfig="headerConfig" @headerBack="headerBack"></pub-head>
        <div class="pub_page_scroll page_box">
            <div class="user_list_box">
                <div class="li" v-for="(li,key) in list" :key="key"
                    @click="$comFun.openWin('/pages/mine/friend_center',{userId:li.onlyId})">
                    <pub-image class="headimg" :src="li.avatar"></pub-image>
                    <div class="text">
                        <div class="name">{{li.nickName}}</div>
                        <!-- <div class="labels">
                            <div class="li" v-for="(la,lkey) in li.labels" :key="lkey">
                                <pub-image class="img" :src="la.coverImg"></pub-image>
                                <div class="txt">{{ la.title }}</div>
                            </div>
                        </div> -->
                    </div>
                </div>
            </div>
            <div v-if="loadFinish && list.length==0">
                <br>
                <br>
                <div class="pub_nodata_1"> 暂未搜索到相关用户</div>
            </div>
        </div>
    </view>
</template>

<script>
export default {
    data() {
        return {
            headerConfig: {
                title_type: 0,
                search_type: 1,
                left_type: 3,
                // header_color: '#f8f8f8',
            },

            list: [],
            loadFinish: false,
        };
    },
    onLoad() {

    },
    methods: {
        headerBack(data) {
            if (data.type == 'search') {
                this.toSearch(data.keyword);
            } else if (data.type == 'searchChange') {
                if (data.keyword == '') {
                    this.list = [];
                    this.loadFinish = false;
                }
            }
        },
        async toSearch(keyword) {
            if (keyword.trim() == '') {
                this.$comFun.toast('请输入用户昵称');
                return;
            }
            this.loadFinish = false;
            this.$comFun.openLoading();
            const res = await this.$request.get('quan/getConnectionsInfoByNickName', {
                key: keyword
            });
            this.$comFun.closeLoading();
            // console.log(res);
            this.loadFinish = true;
            if (res.code == 200) {
                this.list = [res.result];
            } else {
                this.list = [];
            }
        }
    },
};
</script>

<style lang="scss" scoped>
@import "@/common/css/chat.scss";
</style>
